package com.daoyin.ssph.frontAction;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import com.daoyin.ssph.bean.Honor;
import com.daoyin.ssph.bean.Message;
import com.daoyin.ssph.service.MessageService;

public class MessageAction {
	private MessageService ma;

	
	public void setMa(MessageService ma) {
		this.ma = ma;
	}
	private String id;
	
	private String content;
	private String time;
	public void setId(String id) {
		this.id = id;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public void setTime(String time) {
		this.time = time;
	}
	
	public String add() throws UnsupportedEncodingException{
		ServletActionContext.getRequest().setCharacterEncoding("utf-8");
		Message t = new Message();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		time = df.format(new Date());
		t.setContent(content);
		t.setTime(time);
		String str = ma.add(t);
		if(("success").equals(str)){
			return "success";
		}
		return "fail";			
	}

	public String show(){
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Message> list = ma.query();
		
		request.setAttribute("show", list);
		return "success";
	}
	/*public String showMap(){
		id = "1";
		HttpServletRequest request = ServletActionContext.getRequest();
		
		Message message = ma.query(Integer.parseInt(id));
		request.setAttribute("message", message);
		return "success";
		
	}*/
	
}
